/**
 * @date   2011-5-7
 * @author tianye
 */
package cn.edu.dlut.WingGame.Game;

import cn.edu.dlut.WingGame.BaseType.ObjectState;
import cn.edu.dlut.WingGame.Graphic.GLDevice;
import cn.edu.dlut.WingGame.Object.WingObject;
import cn.edu.dlut.WingGame.Tools.ObjectContainer;

public class WingScene extends WingObject {
	protected float alpha = 1.0f;
	protected float skewingX = 0;
	protected float skewingY = 0;
	public ObjectContainer mObject;

	public WingScene() {
		mObject = new ObjectContainer();
	}

	public WingScene(String name) {
		super(name);
		mObject = new ObjectContainer();
	}

	public boolean addLayer(WingObject layer) {
		return mObject.addObject(layer);
	}

	public WingObject getLayer(int id) {

		return mObject.getObjectByID(id);
	}

	public WingObject getLayer(String name) {

		return mObject.getObjectByID(WingObject.NameToID(name));
	}

	@Override
	public void update() {
		WingObject obj;
		for (int i = 0; i < mObject.getSize(); i++) {
			obj = mObject.getObject(i);
			if (obj.mState == ObjectState.died)
				mObject.delObjectByID(obj.getID());
			else if (obj.mState == ObjectState.normal
					|| obj.mState == ObjectState.update)
				obj.update();
		}
	}

	@Override
	public void render() {
		WingObject obj;
		float tmp_a = GLDevice.getAlpha();
		GLDevice.setAlpha(alpha * tmp_a);
		GLDevice.skewingXY(skewingX, skewingY);
		for (int i = 0; i < mObject.getSize(); i++) {
			obj = mObject.getObject(i);
			if (obj.mState == ObjectState.died)
				mObject.delObjectByID(obj.getID());
			else if (obj.mState == ObjectState.normal
					|| obj.mState == ObjectState.render)
				obj.render();
		}
		GLDevice.skewingXY(-skewingX, -skewingY);
		GLDevice.setAlpha(tmp_a);
	}

	public void setAlpha(float alpha) {
		this.alpha = alpha;
	}

	public float getAlpha() {
		return alpha;
	}

	public void setSkewingX(float skewingX) {
		this.skewingX = skewingX;
	}

	public float getSkewingX() {
		return skewingX;
	}

	public void setSkewingY(float skewingY) {
		this.skewingY = skewingY;
	}

	public float getSkewingY() {
		return skewingY;
	}
}
